#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define FS4412_LED_ON  0x10
#define FS4412_LED_OFF 0x20

struct msg
{
	long type;
	unsigned char text[N];
};

struct msg msg_buf = {0, {0}};



int main(void)
{
	int buf[128] = {0};
	int fd = open("/dev/led2", O_RDWR);
	if(fd < 0){
		printf("open error\n");
	}

	
	key_t key; 
	int msgid; 
	char device[6] = {0};

	memset(&msg_buf, 0, sizeof(msg_buf));
	
	if((key = ftok("/", 'b')) < 0)
	{
		perror("ftok");
		exit(1);
	}

	msgid = msgget(key,IPC_CREAT|IPC_EXCL|0666);
	if(msgid == -1)
	{
		if(errno == EEXIST)
		{
			msgid = msgget(key, 0666);
		}
		else{
		perror("msgget");
		exit(1);
		}
	}
	
	
	
	
	
	
	
	
	
	

	while(1)
	{
			msgrcv(msgid, &msg_buf, sizeof(msg_buf) - sizeof(long), 2L, 0);
            
			
			
			if(msg_buf.text[0] == (1 << (1 + 4)) | (1 << 1))
			{
			ioctl(fd, FS4412_LED_ON);
            }
			
			if(msg_buf.text[0] == (1 << (1 + 4)) )
			{          
				ioctl(fd, FS4412_LED_OFF);
			}			
			if(msg_buf.text[0] == (1 << (2 + 4)) | (1 << 2))
			 {
			 ioctl(fd, FS4413_LED_ON);
             }
			 
			 if(msg_buf.text[0] == (1 << (2 + 4)) )
           
			{
			ioctl(fd, FS4413_LED_OFF);
            }
			
        }
	

    
	close(fd);

	return 0;
}

